<?php
class AutoLoadClass{
	private static $_self;
	private $_dirs = array();
	public static function single(){
		if(self::$_self instanceof AutoLoadClass){
			return self::$_self;
		}else{
			self::$_self = new AutoLoadClass;
		}
		return self::$_self;
	}
	private function __construct(){
		$this->_dirs[] = APP_DIR."Libs/Class/";
	}
	public function regDir($path){
		if(is_array($path)){
			foreach($path AS $val){
				if(strpos($val,"/") !== (strlen($val) - 1)){
					$val .= "/";
				}
				$this->_dirs[] = $val;
			}
		}else{
			if(strpos($path,"/") !== (strlen($path) - 1)){
				$path .= "/";
			}
			$this->_dirs[] = $path;
		}
	}
	public function __autoload($class){
		$list = explode("_", $class);
		if(count($list) > 0){
			$path = implode("/",$list);
			foreach($this->_dirs AS $val){
				if(file_exists($val.$path.".class.php")){
					return include $val.$path.".class.php";
				}
			}
		}else{
			foreach($this->_dirs AS $val){
				if(file_exists($val.$class.".class.php")){
					return include $val.$class.".class.php";
				}
			}
		}
		trigger_error("找不到累:".$class);
	}
	public function run(){
		spl_autoload_register(array($this,"__autoload"));
	}
	
}
